const request = require("./request")
// 获取当前ip的地址
async function reqPosition(key) {
    try {
        let result = await request.get(`/v3/ip?key=${key}`)
        return result
    } catch (error) {
        return Promise.reject(error)
    }
}
// 获取输入省区的坐标
// key  查询关键字 子级行政区 第几页
async function reqDistrict({ key, keywords, subdistrict, page }) {
    try {
        let result = await request.get(`/v3/config/district?key=${key}&keywords=${keywords}&subdistrict=${0}`)
        return result   
    } catch (error) {
        return Promise.reject(error)

    }
}
//  根据坐标获取位置信息
                                   	
//   key  经纬度坐标  返回附近POI类型  搜索半径
async function getRegeo({ key, location, poitype, radius }){
    try {
        let result=await request.get(`/v3/geocode/regeo?key=${key}&location=${location}&poitype=${poitype}&radius=${radius}`)
        return result
    } catch (error) {  
        return Promise.reject(error)
    }
}
async function searchHint({key,keywords,type,location,city}){
    try {
        let result=await request.get(`/v3/assistant/inputtips?key=${key}&keywords=${keywords}&type=${type}&location=${location}&city=${city}`)
        return result
    } catch (error) {
        return Promise.reject(error)
    }
}
module.exports = {
    reqPosition,
    reqDistrict,
    getRegeo,
    searchHint
}